package cz.khfotbal.beans;

import java.util.List;

import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import cz.khfotbal.domain.Administrator;
import cz.khfotbal.service.AdminService;

@Component
@Scope(value = "session")
public class AdminBean {
	
	@Autowired
	private AdminService adminService;
	
	private Administrator newAdmin;
	private Administrator selectedAdmin;
	
	public AdminBean(){
		newAdmin = new Administrator();
	}
	
	public List<Administrator> getAdminList(){
		return adminService.getAllAdmin();
	}
	
	public void updateAdmin(){
		if (selectedAdmin != null){
			adminService.updateAdmin(selectedAdmin);
		}
	}
	
	public void deleteAdmin(){
		if (selectedAdmin != null){
			adminService.deleteAdmin(selectedAdmin);
		}
	}
	
	public void createAdmin(){
		newAdmin.setEnabled(true);
		newAdmin.setAuthority("ROLE_USER");
		adminService.createAdmin(newAdmin);
		newAdmin = new Administrator();
	}

	public Administrator getNewAdmin() {
		return newAdmin;
	}

	public void setNewAdmin(Administrator newAdmin) {
		this.newAdmin = newAdmin;
	}

	public Administrator getSelectedAdmin() {
		return selectedAdmin;
	}

	public void setSelectedAdmin(Administrator selectedAdmin) {
		this.selectedAdmin = selectedAdmin;
	}
	

}
